const nav = navigator && navigator.userAgent ? navigator.userAgent : '';
let storage = null;
if (nav.indexOf("Windows") >= 0) {
  storage = localStorage
}
if (!storage) {
  throw new Error("no storage can be use!")
}

function setItem(key: string, value: string): void {
  if (!key || !value) {
    throw new Error("key or value can't be null!");
  }
  const nav = navigator && navigator.userAgent ? navigator.userAgent : '';
  let storage = null;
  if (nav.indexOf("Windows") >= 0) {
    storage = localStorage
  }
  if (!storage) {
    throw new Error("no storage can be use!")
  }
  storage.setItem(key, value);

}

function getItem(key: string): string {
  const value = storage.getItem(key);
  return value as string
}

function removeItem(key: string) {
  storage.removeItem(key)
}

export {setItem, getItem, removeItem}
